package ${apiPackage};

import org.springframework.stereotype.Service
import ${apiPackage}.${apiName}
import ${modelPackage}.${modelName}
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
<#if enableSwagger3>
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
</#if>

/**
* ${tableComment} API
* @author ${author}
* @since ${date}
*/
@RestController
@RequestMapping("/${tableName}")
<#if enableSwagger3>
@Tag(name = "${tableComment} API")
</#if>
open class ${controllerName}(
    private val ${apiName?uncap_first}: ${apiName}
){

<#if enableSwagger3>
    @Operation(summary = "新增数据")
<#else>
    /**
     * 插入新数据
     * @author ${author}
     * @since ${date}
     * @param model:
    */
</#if>
    @PostMapping("")
    fun insert(@RequestBody @Validated model: ${modelName}){
        ${apiName?uncap_first}.insert(model)
    }

<#if primaryColumn?? && (primaryColumn?size == 1)>
    <#if enableSwagger3>
    @Operation(summary = "根据ID删除记录")
    <#else>
    /**
      * 根据ID删除记录
      * @author ${author}
      * @since ${date}
      * @param id:
    */
    </#if>
    @DeleteMapping("/{id}")
    fun deleteById(@PathVariable("id") id: ${primaryColumn[0].javaType}){
        ${apiName?uncap_first}.deleteById(id)
    }

    <#if enableMyBatisPlus>
    @Operation(summary = "更新记录")
    <#else>
    /**
      * 根据ID更新记录
      * @author ${author}
      * @since ${date}
      * @param model:
    */
    </#if>
    @PutMapping("/{id}")
    fun update(@PathVariable("id") id: ${primaryColumn[0].javaType},@RequestBody @Validated model: ${modelName}){
        model.${primaryColumn[0].javaFiled} = id
        ${apiName?uncap_first}.updateSelectiveById(model)
    }

    <#if enableMyBatisPlus>
    @Operation(summary = "查询详情")
    <#else>
    /**
      * 根据ID查询记录
      * @author ${author}
      * @since ${date}
      * @param id:
      * @return ${modelPackage}.${modelName}
      */
    </#if>
    @GetMapping("/{id}")
    fun getById(@PathVariable("id") id: ${primaryColumn[0].javaType}): ${modelName}?{
        return ${apiName?uncap_first}.selectById(id)
    }

</#if>

}

